class_name BuffPanel
extends Panel


@export var buff_btns: Array[BuffButton]
@export var buffs: Array[Buff]

signal choose_buff_finished


func _ready() -> void:
    var btn_group := ButtonGroup.new()
    for btn in buff_btns:
        btn.button_group = btn_group
        
    btn_group.pressed.connect(
        func(btn: BuffButton):
            if btn.buff == null: return
            btn.buff.use(get_tree().get_first_node_in_group("player"))
            btn.button_pressed = false      # 防止再次显示时，无法显示hover样式
            choose_buff_finished.emit()
    )



func _random_buffs() -> void:
    for btn in buff_btns:
        var buff: Buff = buffs.pick_random()
        buff.update_modified_value(0)
        btn.buff = buff.duplicate()


func display(value: bool) -> void:
    if value:
        _random_buffs()
    visible = value

